/*
 * RenderStateList.java
 * 
 * Created on Jun 11, 2007, 10:38:58 PM
 * 
 * Copyright (c) 2007 Daniel Gronau
 *
 * This file is part of KanjiTori.
 *
 * KanjiTori is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * KanjiTori is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */

package kanjitori.map;

import kanjitori.graphics.*;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.state.CullState;
import com.jme.scene.state.RenderState;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import kanjitori.abstraction.Parameterizable;
import kanjitori.util.GraphicUtil;
import kanjitori.util.Parameters;

/**
 *
 * @author DGronau
 */
class RenderStateHolder implements Parameterizable {

    private final static String TEXTURE = "texture";
    private final static String COLOR = "color";
    private final static String CULL="cull";
    
    private String name;
    private Map<String, String> params;
    
    /**
     * 
     * @param name identifier 
     */
    public RenderStateHolder(String name) {
        this.name = name;
    }
    
    public String getName() {
        return name;
    }

    public void setParams(Map<String, String> map) {
        this.params = map;
    }

    public Map<String, String> getParams() {
        return params;
    }
    
    public List<RenderState> getRenderStates() {
        List<RenderState> list = new ArrayList<RenderState>();
        String texture = params.get(TEXTURE);
        if (texture != null) {
            list.add(GraphicUtil.loadTexture(texture, true));
        }
        ColorRGBA color = Parameters.getColorRGBA(params.get(COLOR));
        if(color != null) {
            list.add(GraphicUtil.getMaterialState(color));
        }
        String cull = params.get(CULL);
        if (cull != null) {
            int mode = -1;
            if (cull.equalsIgnoreCase("front")) {
                mode = CullState.CS_FRONT;
            } else if (cull.equalsIgnoreCase("back")) {
                mode = CullState.CS_BACK;
            } else if (cull.equalsIgnoreCase("front and back")) {
                mode = CullState.CS_FRONT_AND_BACK;
            } else if (cull.equalsIgnoreCase("none")) {
                mode = CullState.CS_NONE;
            }
            if (mode != -1) {
                list.add(GraphicUtil.getCullState(mode));
            }
        }
        return list;
    }

    

}
